import React from "react";
import Radio from "../../../Radio";
import type { FieldBaseType } from "../../type";

export default function BooleanField({
  field,
  isValid,
  onChange,
}: {
  field: FieldBaseType<boolean>;
  isValid: boolean;
  onChange: (v: boolean) => void;
}) {
  const { value, defaultValue, disabled } = field;

  return (
    <Radio<boolean>
      value={value ?? defaultValue}
      className={isValid ? undefined : "boolean-invalid"}
      onChange={onChange}
      border
      disabled={disabled}
      options={[
        { value: true, label: "是" },
        { value: false, label: "否" },
      ]}
    />
  );
}
